package cn.sx213.mongodb.controller;

import cn.sx213.mongodb.entity.Employee;
import cn.sx213.mongodb.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author liliang
 * @Description:
 * @Date 18/1/4 下午5:43
 */
@Controller
public class DemoController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/age/{age}")
    @ResponseBody
    public List<Employee> home(@PathVariable("age") Integer age) {
        List<Employee> employeeList = employeeService.getEmployeeListByAge(age);
        return employeeList;
    }

    @RequestMapping("/name/{name}")
    @ResponseBody
    public Employee hello(@PathVariable("name") String name) {
        Employee employee = employeeService.getEmployeeByName(name);
        return employee;
    }

    @RequestMapping("/hello")
    @ResponseBody
    public String hello() {
        return "springboot";
    }

    @RequestMapping("/{name}/{age}")
    @ResponseBody
    public List<Employee> hello(@PathVariable("name") String name, @PathVariable("age") Integer age) {
        return employeeService.getEmployee(name, age);
    }


}
